package com.ayu.chatroom.service.impl;

import com.ayu.chatroom.entity.ChatMsg;
import com.ayu.chatroom.mapper.ChatMsgMapper;
import com.ayu.chatroom.service.ChatMsgService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ayu
 * @since 2022-10-10
 */
@Service
public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsg> implements ChatMsgService {

    @Override
    public void updateMsgSigned(List<String> msgIdList) {

        UpdateWrapper<ChatMsg> updateWrapper = new UpdateWrapper<>();

        updateWrapper.in(CollectionUtils.isNotEmpty(msgIdList),"id",msgIdList);

        updateWrapper.set("sign_flag",1);

        this.update(updateWrapper);


    }

    @Override
    public List<ChatMsg> getUnReadMsgList(String acceptUserId) {

        QueryWrapper<ChatMsg> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("sign_flag",0);

        queryWrapper.eq(StringUtils.isNotEmpty(acceptUserId),"accept_user_id",acceptUserId);

        List<ChatMsg> list = this.list(queryWrapper);
        return list;
    }

}
